<template>
  <div>
    <h1>This is an login page</h1>
    <p>
      {{ $route.query.code }}
    </p>
  </div>
</template>

<script lang="ts" setup>
import axios from 'axios'
import { useRoute, useRouter } from 'vue-router'
import { onMounted } from 'vue'
import { useCounterStore } from '../stores/counter'

const counterStore = useCounterStore()
const route = useRoute()
const router = useRouter()

onMounted(() => {
  const code = route.query.code
  if (route.query.code) {
    axios.get(`http://localhost:8080/doLogin?code=${code}`).then((resp) => {
      if (resp.data.code == '2000000') {
        counterStore.setUserInfo(resp.data.data)
        router.push('/')
      }
    })
  }
})
</script>
